-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[ClangImporter] Attach _SwiftifyImportProtocol to imported protocols with bounds attributes #85123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
...with bounds attributes This creates safe overloads for any methods in the protocol annotated with bounds information. Updates _SwiftifyImportProtocol to make the added overloads in the protocol public. rdar://144335990
|
@swift-ci please smoke test |
|
@swift-ci please smoke test |
This updates SwiftifyImportProtocolPrinter such that it no longer emits
anything for methods without bounds or lifetime info. Previously we
would not attach the macro if no methods in the protocol contained
bounds or lifetime info. However if one of the methods did, we would
still emit `.method(signature: "func foo()", paramInfo: [])` for the
methods without bounds of lifetime info. This would result in overloads
being generated, like so:
```
@_alwaysEmitIntoClient @_disfavoredOverload public
func foo() {
return unsafe foo()
}
```
As part of this change, SwiftifyImportPrinter is now an abstract parent
type for SwiftifyImportProtocolPrinter, and the new
SwiftifyImportFunctionPrinter. Instead of SwiftifyImportProtocolPrinter
inheriting the function printing, `printMethod` instead creates a new
SwiftifyImportFunctionPrinter each time, with a new output string. If it
output anything interesting the result is forwarded, otherwise it is
discarded.
|
@swift-ci please smoke test |
1 similar comment
|
@swift-ci please smoke test |
|
@swift-ci please smoke test windows platform |
1 similar comment
|
@swift-ci please smoke test windows platform |
3b9ea2f to
1c0c558
Compare
|
@swift-ci please smoke test |
|
For a second I was questioning whether |
|
ping @egorzhdan @j-hui @DougGregor |
j-hui
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, aside from a couple of nits. But I'm not very familiar with how ObjC protocols are imported so would prefer if this were reviewed by someone else too.
| let hasVisibilityModifier = method.modifiers.contains { modifier in | ||
| let modName = modifier.name.trimmed.text | ||
| return modName == "public" || modName == "internal" || modName == "open" | ||
| || modName == "private" || modName == "filePrivate" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if the scenario is reachable, but you're missing package, and filePrivate is spelled all lowercase. I think you can simplify this to:
| let hasVisibilityModifier = method.modifiers.contains { modifier in | |
| let modName = modifier.name.trimmed.text | |
| return modName == "public" || modName == "internal" || modName == "open" | |
| || modName == "private" || modName == "filePrivate" | |
| } | |
| let hasVisibilityModifier = method.modifiers.contains { | |
| return switch $0.name.trimmed.text { | |
| case "open", "public", "package", "internal", "fileprivate", "private": true | |
| default: false | |
| } | |
| } |
| else // decls imported from clang do not have a SourceFile | ||
| ASSERT(isa<FileUnit>(dc) && !isa<SourceFile>(dc)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: put the comment in the assertion
| else // decls imported from clang do not have a SourceFile | |
| ASSERT(isa<FileUnit>(dc) && !isa<SourceFile>(dc)); | |
| else | |
| ASSERT(isa<FileUnit>(dc) && !isa<SourceFile>(dc) && "decls imported from Clang should not have a SourceFile"); |
This creates safe overloads for any methods in the protocol annotated with bounds information.
To support code sharing for both
clang::FunctionDeclandclang::ObjCMethodDecl,swiftifyImplis templated.Updates _SwiftifyImportProtocol to make the added overloads in the protocol public.
rdar://144335990